import requests

# 设置 API 地址和认证信息
url = "https://api.siliconflow.cn/v1/audio/transcriptions"
api_key = "sk-svuwiezizbxyflaqnhapzgijjdmeiaotknizeezdwzesoruw"  # 替换为你的实际 API 密钥
audio_file_path = "./data/emo_3.wav"  # 替换为你的音频文件路径

# 构造请求数据
headers = {
    "Authorization": f"Bearer {api_key}"
}

# 读取音频文件并构造 multipart/form-data 请求
with open(audio_file_path, "rb") as audio_file:
    # files = {
    #     "file": (audio_file_path.split("/")[-1], audio_file, "audio/wav")  # 自动识别文件名和 MIME 类型
    # }

    files = {
        "file": audio_file  # 自动识别文件名和 MIME 类型
    }
    
    data = {
        "model": "FunAudioLLM/SenseVoiceSmall"  # 使用文档推荐的模型
    }
    
    # 发送 POST 请求
    response = requests.post(url, headers=headers, files=files, data=data)
print(response)
# 处理响应结果
if response.status_code == 200:
    result = response.json()
    print(result)
    print("转写结果:", result["text"])
else:
    print(f"请求失败，状态码: {response.status_code}")
    print("错误信息:", response.text)